﻿<%@ WebHandler Language="C#" Class="ProblemsTypeHandler" %>

using System.Data;
using System.Text;
using Dln.Common;
using Dln.Common.Helper;
using System.Collections.Generic;
using Dln.Model;
using System;
using System.Web;
using System.Web.Script.Serialization;

public class ProblemsTypeHandler : HandlerBase
{

    public void GetProblemsTypeTable()
    {
        var param = CommonHelper.GetDataGridParam(_httpRequestForm);
        Dictionary<string, string> queryDic = CommonHelper.StringToDictionary(param.Query);
        StringBuilder strwhere = new StringBuilder();
        strwhere.Append(" DelStatus=0 ");
        PagingInfo pageInfo = new PagingInfo()
        {
            TableName = "ProblemTypes",
            Fields = "*",
            PrimaryKey = "Id",
            Where = strwhere.ToString(),
            //Order = param.SortName + " " + param.SortOrder,
            PageSize = param.RP,
            PageIndex = param.Page
        };

        int totalCount;
        DataTable dt = SqlHelper.GetPageTable(out totalCount, pageInfo);



        var jquerygridobject = new JqueryGridObject
        {
            DataGridParam = param,
            total = totalCount,
            QueryDataTable = dt
        };
        string jsonText = JSONHelper.JqueryGridObjectToJson(jquerygridobject);
        Context.Response.Write(jsonText);
    }


    /// <summary>
    /// 添加问题分类
    /// </summary>
    public void AddArticle()
    {
        string strArticleType = _httpRequestForm["txtAddName"].ToString();

        var problemsTypeModel = new ProblemTypes();
        problemsTypeModel.AddTime = DateTime.Now;
        problemsTypeModel.TypeName = strArticleType;


        var count1 = SqlHelper.Context.Insert<ProblemTypes>(problemsTypeModel);
        if (count1 > 0)
        {
            PrintErrorJson("发布成功！");
            return;
        }
        PrintErrorJson("发布失败！");
    }

    /// <summary>
    /// 编辑问题分类
    /// </summary>
    public void EditArticleType()
    {
        string strArticleType = _httpRequestForm["txtEditName"].ToString();

        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);
        var problemTypes = SqlHelper.Context.From<ProblemTypes>().Where(d => d.Id == IDPlus).ToFirstDefault();
        if (problemTypes == null)
        {
            PrintErrorJson("不存在要修改的数据");
            return;
        }

        problemTypes.AddTime = DateTime.Now;
        problemTypes.TypeName = strArticleType;

        var count1 = SqlHelper.Context.Update<ProblemTypes>(problemTypes);
        if (count1 > 0)
        {
            PrintSuccessJson("修改成功！");
            return;
        }
        PrintErrorJson("修改失败！");
    }



    /// <summary>
    /// 删除问题分类
    /// </summary>
    public void DeleteArticleType()
    {
        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);

        var uptModel = SqlHelper.Context.From<ProblemTypes>().Where(d => d.Id == IDPlus).First();
        if (uptModel == null)
        {
            PrintErrorJson("不存在要删除的数据");
            return;
        }

        var count = SqlHelper.Context.Delete<ProblemTypes>(IDPlus);
        if (count > 0)
        {
            PrintSuccessJson("删除成功！");
            return;
        }
        PrintErrorJson("删除失败！");
    }

    /// <summary>
    /// 拉取接口列表
    /// </summary>
    public void GetInterfacesTypesTable()
    {
        var param = CommonHelper.GetDataGridParam(_httpRequestForm);
        Dictionary<string, string> queryDic = CommonHelper.StringToDictionary(param.Query);
        StringBuilder strwhere = new StringBuilder();
        strwhere.Append(" DelStatus=0 ");
        PagingInfo pageInfo = new PagingInfo()
        {
            TableName = "InterfacesTypes",
            Fields = "*",
            PrimaryKey = "Id",
            Where = strwhere.ToString(),
            //Order = param.SortName + " " + param.SortOrder,
            PageSize = param.RP,
            PageIndex = param.Page
        };

        int totalCount;
        DataTable dt = SqlHelper.GetPageTable(out totalCount, pageInfo);
        var jquerygridobject = new JqueryGridObject
        {
            DataGridParam = param,
            total = totalCount,
            QueryDataTable = dt
        };
        string jsonText = JSONHelper.JqueryGridObjectToJson(jquerygridobject);
        Context.Response.Write(jsonText);
    }

    /// <summary>
    /// 添加接口
    /// </summary>
    public void AddInterfaces()
    {
        string strArticleType = _httpRequestForm["txtAddName"].ToString();
        string strDescribe = _httpRequestForm["txtAddDescribe"].ToString();
        var InterfacesModel = new InterfacesTypes();
        InterfacesModel.AddTime = DateTime.Now;
        InterfacesModel.InterfaceName = strArticleType;
        InterfacesModel.Describe = strDescribe;

        var count1 = SqlHelper.Context.Insert<InterfacesTypes>(InterfacesModel);
        if (count1 > 0)
        {
            PrintErrorJson("添加成功！");
            return;
        }
        PrintErrorJson("添加失败！");
    }

    /// <summary>
    /// 编辑接口
    /// </summary>
    public void EditInterfaces()
    {
        string strArticleType = _httpRequestForm["txtEditName"].ToString();
        string strDescribe = _httpRequestForm["txtEditDescribe"].ToString();

        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);
        var InterfacesModel = SqlHelper.Context.From<InterfacesTypes>().Where(d => d.Id == IDPlus).ToFirstDefault();
        if (InterfacesModel == null)
        {
            PrintErrorJson("不存在要修改的数据");
            return;
        }

        InterfacesModel.AddTime = DateTime.Now;
        InterfacesModel.InterfaceName = strArticleType;
        InterfacesModel.Describe = strDescribe;

        var count1 = SqlHelper.Context.Update<InterfacesTypes>(InterfacesModel);
        if (count1 > 0)
        {
            PrintSuccessJson("修改成功！");
            return;
        }
        PrintErrorJson("修改失败！");
    }



    /// <summary>
    /// 删除接口
    /// </summary>
    public void DeleteInterfaces()
    {
        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);

        var uptModel = SqlHelper.Context.From<InterfacesTypes>().Where(d => d.Id == IDPlus).First();
        if (uptModel == null)
        {
            PrintErrorJson("不存在要删除的数据");
            return;
        }

        var count = SqlHelper.Context.Delete<InterfacesTypes>(IDPlus);
        if (count > 0)
        {
            PrintSuccessJson("删除成功！");
            return;
        }
        PrintErrorJson("删除失败！");
    }

    /// <summary>
    /// 拉取角色列表
    /// </summary>
    public void GetPositionTypesTable()
    {
        var param = CommonHelper.GetDataGridParam(_httpRequestForm);
        Dictionary<string, string> queryDic = CommonHelper.StringToDictionary(param.Query);
        StringBuilder strwhere = new StringBuilder();
        strwhere.Append(" DelStatus=0 ");
        PagingInfo pageInfo = new PagingInfo()
        {
            TableName = "PositionTypes",
            Fields = "*",
            PrimaryKey = "Id",
            Where = strwhere.ToString(),
            //Order = param.SortName + " " + param.SortOrder,
            PageSize = param.RP,
            PageIndex = param.Page
        };

        int totalCount;
        DataTable dt = SqlHelper.GetPageTable(out totalCount, pageInfo);



        var jquerygridobject = new JqueryGridObject
        {
            DataGridParam = param,
            total = totalCount,
            QueryDataTable = dt
        };
        string jsonText = JSONHelper.JqueryGridObjectToJson(jquerygridobject);
        Context.Response.Write(jsonText);
    }

    /// <summary>
    /// 添加角色
    /// </summary>
    public void AddPositionTypes()
    {
        string strArticleType = _httpRequestForm["txtAddName"].ToString();
        var positionModel = new PositionTypes();
        positionModel.AddTime = DateTime.Now;
        positionModel.TypeName = strArticleType;

        var count1 = SqlHelper.Context.Insert<PositionTypes>(positionModel);
        if (count1 > 0)
        {
            PrintErrorJson("添加成功！");
            return;
        }
        PrintErrorJson("添加失败！");
    }

    /// <summary>
    /// 编辑角色
    /// </summary>
    public void EditPositionTypes()
    {
        string strArticleType = _httpRequestForm["txtEditName"].ToString();

        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);
        var positionModel = SqlHelper.Context.From<PositionTypes>().Where(d => d.Id == IDPlus).ToFirstDefault();
        if (positionModel == null)
        {
            PrintErrorJson("不存在要修改的数据");
            return;
        }

        positionModel.AddTime = DateTime.Now;
        positionModel.TypeName = strArticleType;

        var count1 = SqlHelper.Context.Update<PositionTypes>(positionModel);
        if (count1 > 0)
        {
            PrintSuccessJson("修改成功！");
            return;
        }
        PrintErrorJson("修改失败！");
    }



    /// <summary>
    /// 删除角色
    /// </summary>
    public void DeletePositionTypes()
    {
        int IDPlus = Convert.ToInt32(_httpReuqestString["IDPlus"]);

        var uptModel = SqlHelper.Context.From<PositionTypes>().Where(d => d.Id == IDPlus).First();
        if (uptModel == null)
        {
            PrintErrorJson("不存在要删除的数据");
            return;
        }

        var count = SqlHelper.Context.Delete<PositionTypes>(IDPlus);
        if (count > 0)
        {
            PrintSuccessJson("删除成功！");
            return;
        }
        PrintErrorJson("删除失败！");
    }

    /// <summary>
    /// 拉取接口列表
    /// </summary>
    public void GetInterfacesTypes()
    {
        var interfacesType = SqlHelper.Context.From<InterfacesTypes>().ToList();

        Context.Response.Write(JSONHelper.ObjectToJson(interfacesType));
    }

    /// <summary>
    /// 设置角色权限
    /// </summary>
    public void AddInterfacesPosition()
    {
        int idplus = Convert.ToInt32(_httpReuqestString["IDPlus"]);
        string sku = _httpReuqestString["Skus"].TrimEnd(',');

        var positionModel = SqlHelper.Context.From<PositionTypes>().Where(d => d.Id == idplus);
        if (positionModel == null || positionModel.Count() <= 0)
        {
            PrintErrorJson("不存在要修改的数据");
            return;
        }

        var model = positionModel.ToFirstDefault();
        model.AddTime = DateTime.Now;
        model.Interfaces = sku;

        var count1 = SqlHelper.Context.Update<PositionTypes>(model);
        if (count1 > 0)
        {
            PrintSuccessJson("修改成功！");
            return;
        }
        PrintErrorJson("修改失败！");
    }


    /// <summary>
    /// 拉取接口列表
    /// </summary>
    public void Getdt_type_listTable()
    {
        var positionModel = SqlHelper.ContextDlnOnline.From<dt_type_list>().ToList();
        Context.Response.Write(JSONHelper.ObjectToJson(positionModel));
    }

    /// <summary>
    /// 设置类别
    /// </summary>
    public void AddWechartType()
    {
        int idplus = Convert.ToInt32(_httpReuqestString["IDPlus"]);
        string sku = _httpReuqestString["Skus"].TrimEnd(',');

        var WeChatUsersModel = SqlHelper.Context.From<WeChatUsers>().Where(d => d.Id == idplus);
        if (WeChatUsersModel == null || WeChatUsersModel.Count() <= 0)
        {
            PrintErrorJson("不存在要修改的数据");
            return;
        }

        var model = WeChatUsersModel.ToFirstDefault();
        model.AddTime = DateTime.Now;
        model.Category = sku;

        var count1 = SqlHelper.Context.Update<WeChatUsers>(model);
        if (count1 > 0)
        {
            PrintSuccessJson("修改成功！");
            return;
        }
        PrintErrorJson("修改失败！");
    }



}